package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.flowable.dto.FlowFormEventDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.FlowFormEvent;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class FlowFormEventConverter {

    public static FlowFormEventDto do2Dto(FlowFormEvent domain) {
        if (Objects.isNull(domain)) {
            return null;
        }
        FlowFormEventDto dto = FlowFormEventMapper.INSTANCE.do2Dto(domain);
        dto.setEventReportDocList(AppendixConverter.do2Dto(domain.getEventReportDocList()));
        dto.setDetailImproves(FlowFormEventDetailImproveConverter.do2Dto(domain.getDetailImproves()));
        return dto;
    }

    public static List<FlowFormEventDto> do2Dto(List<FlowFormEvent> domainList) {
        return CollectionUtils.isEmpty(domainList) ? java.util.Collections.emptyList() : domainList.stream().map(FlowFormEventConverter::do2Dto).collect(Collectors.toList());
    }

    public static FlowFormEvent dto2Do(FlowFormEventDto dto) {
        if (Objects.isNull(dto)) {
            return null;
        }
        FlowFormEvent domain = FlowFormEventMapper.INSTANCE.dto2Do(dto);
        domain.setEventReportDocList(AppendixConverter.dto2Do(dto.getEventReportDocList()));
        domain.setDetailImproves(FlowFormEventDetailImproveConverter.dto2Do(dto.getDetailImproves()));
        return domain;
    }

    public static List<FlowFormEvent> dto2Do(List<FlowFormEventDto> dtoList) {
        return CollectionUtils.isEmpty(dtoList) ? java.util.Collections.emptyList() : dtoList.stream().map(FlowFormEventConverter::dto2Do).collect(Collectors.toList());
    }

    @Mapper(componentModel = "spring")
    public interface FlowFormEventMapper {

        FlowFormEventMapper INSTANCE = Mappers.getMapper(FlowFormEventMapper.class);

        FlowFormEventDto do2Dto(FlowFormEvent domain);

        List<FlowFormEventDto> do2Dto(List<FlowFormEvent> domain);

        FlowFormEvent dto2Do(FlowFormEventDto dto);

        List<FlowFormEvent> dto2Do(List<FlowFormEventDto> dto);
    }
}
